package com.atom.common.util;

import java.util.Calendar;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.atom.common.dao.NumberDao;

/**
 * Title: SerialNumberGenerateUtil
 * Description: 生成单据编号和入馆号
 * @author WEWE
 * @date 2016年11月10日 下午3:36:37
 * @version 1.0
 */
@Component
public class SerialNumberGenerateUtil {

  @Resource NumberDao numberDao;

  /**
   * Description: 生成单据编号
   * @param procDefKey
   * @return
   */
//  public synchronized String getSerialNumber(String procDefKey) {
//    String prefix;
//    switch (procDefKey) {
//      case "zlly" : prefix = "[展]";break;
//      case "xfly" : prefix = "[修]";break;
//      case "zxly" : prefix = "[照相]";break;
//      case "yxly" : prefix = "[影]";break;
//      case "qtly" : prefix = "[观]";break;
//      case "ysly" : prefix = "[钥]";break;
//      case "cpyk" : prefix = "[移]";break;
//      case "cpxgbm" : prefix = "[编]";break;
//      case "cpzx" : prefix = "[销]";break;
//      case "cprz" : prefix = "[入馆]";break;
//      case "pdxz" : prefix = "[增]";break;
//      default : prefix = procDefKey;break;
//    }
//    int middle = Calendar.getInstance().get(Calendar.YEAR);
//    String suffix = fillRight(numberDao.getNumber(procDefKey, middle));
//    return prefix + String.valueOf(middle) + suffix;    
//  }

  /**
   * Description: 生成入馆号
   * @return
   */
  public synchronized String getRuGuanHao() {
    int middle = Calendar.getInstance().get(Calendar.YEAR);
    int suffix = numberDao.getNumber("rgh", middle);
    return String.valueOf(middle)  + "." + String.valueOf(suffix);

  }
  
  public synchronized int findRuGuanNumber() {
    int middle = Calendar.getInstance().get(Calendar.YEAR);
    return numberDao.findNumber("rgh", middle);
  }

  private String fillRight(int number) {
    int max = 4;
    String cc = String.valueOf(number);
    int length = cc.length();
    StringBuffer fi = new StringBuffer();
    for (int i = 0; i < max-length; i++) {
      fi.append("0");
    }
    fi.append(cc);
    return fi.toString();
  }

  /**
   * Description: 生成临时总登记号
   * @return
   */
  public String getZongDengJiHao() {
    int middle = Calendar.getInstance().get(Calendar.YEAR);
    int suffix = numberDao.getNumber("zdjh", middle);
    return "临" + String.valueOf(middle)  + "." + String.valueOf(suffix);
  }

}
